package net.zabuchy.issue.entity;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Cascade;

import net.zabuchy.activities.entity.History_event;
import net.zabuchy.iteration.entity.Iteration;
import net.zabuchy.user.entity.User;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;


@Entity
@Table(name="ISSUE", catalog="quickstart")
public class Issue implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private int issueId;
	private String author;
	private byte confirmed;
	private Date creationDate;
	private int customerId;
	private String description;
	private int estimationHours;
	private Date estimationTime;
	private String priority;
	private int projectId;
	private String status;
	private String team;
	private String title;
	private String type;
	private Iteration iteration;
	private IssueDetail issueDetail;
	private Set<History_event> history = new HashSet<History_event>(0);
	private Set<User> users = new HashSet<User>(0); // user pracujacy nad issue, najczesciej bedzie tylko jeden
	private Set<Attachment> attachments = new HashSet<Attachment>(0);
	private Set<IssueLink> issueLinks = new HashSet<IssueLink>(0);
	private Set<Notification> notifications = new HashSet<Notification>(0);

    public Issue() {
    }

    
    
    public Issue(String author, byte confirmed, Date creationDate,
			int customerId, String description, int estimationHours,
			Date estimationTime, String priority, int projectId, String status,
			String team, String title, String type, Iteration iteration,
			IssueDetail issueDetail, Set<History_event> history,
			Set<User> users, Set<Attachment> attachments,
			Set<IssueLink> issueLinks, Set<Notification> notifications) {
		super();
		this.author = author;
		this.confirmed = confirmed;
		this.creationDate = creationDate;
		this.customerId = customerId;
		this.description = description;
		this.estimationHours = estimationHours;
		this.estimationTime = estimationTime;
		this.priority = priority;
		this.projectId = projectId;
		this.status = status;
		this.team = team;
		this.title = title;
		this.type = type;
		this.iteration = iteration;
		this.issueDetail = issueDetail;
		this.history = history;
		this.users = users;
		this.attachments = attachments;
		this.issueLinks = issueLinks;
		this.notifications = notifications;
	}



	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="ISSUE_ID", unique=true, nullable = false)
	public int getIssueId() {
		return this.issueId;
	}

	public void setIssueId(int issueId) {
		this.issueId = issueId;
	}

	@Column(name="AUTHOR", nullable = false)
	public String getAuthor() {
		return this.author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}
	
	@Column(name="CONFIRMED")
	public byte getConfirmed() {
		return this.confirmed;
	}

	public void setConfirmed(byte confirmed) {
		this.confirmed = confirmed;
	}

	@Column(name="CREATION_DATE")
	public Date getCreationDate() {
		return this.creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	@Column(name="CUSTOMER_ID", nullable = false)
	public int getCustomerId() {
		return this.customerId;
	}

	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}

	@Column(name="DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	@Column(name="ESTIMATION_HOURS")
	public int getEstimationHours() {
		return this.estimationHours;
	}

	public void setEstimationHours(int estimationHours) {
		this.estimationHours = estimationHours;
	}


    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="ESTIMATION_TIME")
	public Date getEstimationTime() {
		return this.estimationTime;
	}

	public void setEstimationTime(Date estimationTime) {
		this.estimationTime = estimationTime;
	}


	@Column(name="PRIORITY")
	public String getPriority() {
		return this.priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}
	
	@Column(name="PROJECT_ID", nullable = false)
	public int getProjectId() {
		return this.projectId;
	}

	public void setProjectId(int projectId) {
		this.projectId = projectId;
	}

	@Column(name="STATUS")
	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Column(name="TEAM")
	public String getTeam() {
		return this.team;
	}

	public void setTeam(String team) {
		this.team = team;
	}


	@Column(name="TITLE")
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name="TYPE", nullable = false)
	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@OneToOne(fetch = FetchType.EAGER, mappedBy = "issue", cascade = CascadeType.ALL)
	public IssueDetail getIssueDetail() {
		return this.issueDetail;
	}

	public void setIssueDetail(IssueDetail issueDetail) {
		this.issueDetail = issueDetail;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "issue")
	public Set<History_event> getHistory() {
		return history;
	}

	public void setHistory(Set<History_event> history) {
		this.history = history;
	}

	@ManyToMany(fetch=FetchType.EAGER)
	@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
	@JoinTable(name="ASSIGMENTS", catalog="quickstart", joinColumns={
			@JoinColumn(name="ISSUE_ID", nullable=false, updatable=false)},
			inverseJoinColumns = { @JoinColumn(name="USER_ID", nullable=false, updatable=false)})
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ITERATION_ID", nullable = false)
	public Iteration getIteration() {
		return iteration;
	}

	public void setIteration(Iteration iteration) {
		this.iteration = iteration;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "issue")
	public Set<Attachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(Set<Attachment> attachments) {
		this.attachments = attachments;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "issue")
	public Set<IssueLink> getIssueLinks() {
		return issueLinks;
	}

	public void setIssueLinks(Set<IssueLink> issueLinks) {
		this.issueLinks = issueLinks;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "issue")
	public Set<Notification> getNotifications() {
		return notifications;
	}

	public void setNotifications(Set<Notification> notifications) {
		this.notifications = notifications;
	}
	
}